package com.shuw.com.beingfortextproject.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.shuw.com.beingfortextproject.R;
import com.shuw.com.beingfortextproject.adapter.TabAdapter;
import com.shuw.com.beingfortextproject.base.BaseActivity;
import com.shuw.com.beingfortextproject.fragment.TabFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TabTestActivity extends BaseActivity {


	@BindView(R.id.center_title)
	TextView centerTitle;
	@BindView(R.id.toolbar)
	Toolbar toolbar;
	@BindView(R.id.tabLayout)
	TabLayout tabLayout;
	@BindView(R.id.viewPager)
	ViewPager viewPager;
//	@BindView(R.id.fragmentContainer)
//	FrameLayout fragmentContainer;

	private TabFragment tabFragment;
	private TabAdapter mAdapter;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tab_test);

		ButterKnife.bind(this);
		initView();
	}

	private void initView() {
		centerTitle.setText("Tab效果测试页");
		setToolbar(toolbar);


		List<String > titles = new ArrayList<>();
		titles.add("标题一");
		titles.add("标题二");
		titles.add("标题三");

		List<Fragment> fragments = new ArrayList<>();
		fragments.add(new TabFragment());
		fragments.add(new TabFragment());
		fragments.add(new TabFragment());

		mAdapter = new TabAdapter(titles,fragments,getSupportFragmentManager(),mContext);
		viewPager.setAdapter(mAdapter);
		tabLayout.setupWithViewPager(viewPager);
		for (int i = 0; i < tabLayout.getTabCount(); i++) {
			TabLayout.Tab tab = tabLayout.getTabAt(i);
			tab.setCustomView(mAdapter.getTabView(i));
		}
	}
}
